package com.xuecheng.content.controller;

import com.xuecheng.content.model.dto.CoursePreviewDTO;
import com.xuecheng.content.service.ICoursePreviewService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * @description 课程预览接口
 * @author 勾新杰
 * @version 1.0
 * @date 2025/2/16 21:44
 */
@Controller
@RequestMapping("/course-preview")
@RequiredArgsConstructor
@Api(tags = "课程预览接口")
public class CoursePreviewController {

    /**
     * 课程预览
     */
    private final ICoursePreviewService coursePreviewService;

    /**
     * 课程预览
     *
     * @param courseId 课程id
     * @return ModelAndView
     */
    @GetMapping("/{courseId}")
    @ApiOperation("课程预览")
    public ModelAndView preview(@PathVariable("courseId") Long courseId) {
        ModelAndView modelAndView = new ModelAndView();
        CoursePreviewDTO coursePreviewDTO = coursePreviewService.preview(courseId);
        modelAndView.addObject("model", coursePreviewDTO);
        modelAndView.setViewName("course_template"); // 配置了freemarker的suffix为.ftl和template-loader-path: classpath:/templates/
        return modelAndView;
    }
}
